/*
 * udelay.c
 *
 *  Created on: 2021年7月17日
 *      Author: dbw
 */

#include "common.h"
#include "math_util.h"

#define LOG_TAG     "example_udelay"
#define LOG_LEVEL    LOG_LEVEL_VERBOSE
#include "logger.h"

static void mdelay(uint32_t ms)
{
#define UDELAY_MAX  500

    uint32_t delay;
    uint32_t remain = ms * 1000;

    while (remain > 0)
    {
        delay = MATH_MIN(UDELAY_MAX, remain);
        sys_udelay(delay);
        remain -= delay;
    }
}

void udelay_example_run(void)
{
    LOG_I("test udelay");

    for (int i = 0; i < 10; i++)
    {
        LOG_I("%d", i);
        mdelay(1000);
    }
}
